package com.kaiyidiannao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.kaiyidiannao.main.R;
import com.kaiyidiannao.model.bean.ListViewBean;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 闯儿 on 14-4-2.
 */
public class PullToListAdapter extends BaseAdapter {
    private ImageLoader imageLoader;
    private LayoutInflater layoutInflater;
    private List<ListViewBean> list = new ArrayList<ListViewBean>();

    public PullToListAdapter(Context context, List<ListViewBean> list) {
        imageLoader = ImageLoader.getInstance();
        imageLoader.init(ImageLoaderConfiguration.createDefault(context));
        this.list = list;
        this.layoutInflater =LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = null;
        TextView  nameTextView = null;
        TextView  addressTextView = null;
        ListViewBean listViewBean = list.get(position);
        if (convertView==null)
        {
            convertView=layoutInflater.inflate(R.layout.buystreet_item,null);
        }
        imageView = (ImageView) convertView.findViewById(R.id.buyStreet_item_ImageView);
        nameTextView = (TextView) convertView.findViewById(R.id.buyStreet_item_nameTextView);
        addressTextView = (TextView) convertView.findViewById(R.id.buyStreet_item_ownerTextView);
        imageLoader.displayImage(listViewBean.getThumb(),imageView);
        nameTextView.setText(listViewBean.getTitle());
        addressTextView.setText("商家地址:"+listViewBean.getAddress());
        return convertView;
    }
}
